package mymqsender.services;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * create by caoqg on 2021/8/4
 * 功能说明:
 */
@Component
public class MqSender {


    @Autowired
    private RabbitTemplate template;

    public void sendMsg(String msg){
        Message rabbitMq = MessageBuilder.withBody(msg.getBytes())
                .setContentType(MessageProperties.CONTENT_TYPE_JSON)
                .build();
        this.template.convertAndSend("sms.e.myexchange","sms.m.msg", rabbitMq);
    }
}
